﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Assist;
using YArchitech.Controls;

namespace HYElectricSystemDiagram.FormSet
{
	public partial class FormView : HYBaseForm
	{
		public FormView(List<string> lstCurrentView)
		{
			this.InitializeComponent();
			this.lstCurrentViewN = lstCurrentView;
			if (lstCurrentView.Count == 0)
			{
				this.rbNewView.Checked = true;
				this.rbNewView.Enabled = false;
				this.tbNewView.Text = "配电箱系统图_1";
				this.rbView.Enabled = false;
				this.tbView.Enabled = false;
				return;
			}
			foreach (string item in lstCurrentView)
			{
				this.tbView.Items.Add(item);
			}
			this.rbView.Checked = true;
			this.tbView.SelectedIndex = 0;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.rbNewView.Checked)
			{
				this.strViewName = this.tbNewView.Text;
				if (string.IsNullOrEmpty(this.strViewName))
				{
					YJKMessageBox.Information("新建视图名称不能为空！");
					this.tbNewView.Focus();
					return;
				}
				if (this.lstCurrentViewN.Contains(this.strViewName))
				{
					YJKMessageBox.Information("该视图名称已经存在,请重新输入！");
					this.tbNewView.Focus();
					return;
				}
			}
			if (this.rbView.Checked)
			{
				this.strViewName = this.tbView.Text;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnView_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void rbView_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbView.Checked)
			{
				this.tbView.Enabled = true;
				this.tbNewView.Enabled = false;
			}
		}

		private void rbNewView_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbNewView.Checked)
			{
				this.tbView.Enabled = false;
				this.tbNewView.Enabled = true;
				for (int i = 1; i < 100; i++)
				{
					string text = "配电箱系统图_" + i;
					if (!this.lstCurrentViewN.Contains(text))
					{
						this.tbNewView.Text = text;
						return;
					}
				}
			}
		}

		public string strViewName = "";

		private List<string> lstCurrentViewN = new List<string>();
	}
}
